(function ($) {
    $.dataCenterList = function () {
        return {	//书本基本信息
            subjectList: {},
            bookStatus: 0,
            init: function () {
                this.listener();
                this.initLayui();
                this.getUserInfo();
                this.dataList();
            },
            /**
             * 添加各按钮所需要的监听事件
             */
            listener: function () {
                $("#searchInput").keydown(function () {
                    if (event.keyCode == 13) {
                        $.dataCenterList.dataList();
                    }
                });
                $("#searchBtn").click(function () {
                    $.dataCenterList.dataList();
                });

                /**
                 * 点击查看
                 */
                $(".dataList").on('click', ".check", function () {
                    window.top.xhTop.createNewTab("查看资源", SystemConfig.openPlayView + $(this).parents("li").data("fileurl"), true);
                });
            },
            initLayui: function () {
                layui.use(['layer', 'form', 'laypage', 'table'], function () {
                    var $ = layui.jquery, layer = layui.layer, form = layui.form, table = layui.table, laypage = layui.laypage;
                    form.render('checkbox');
                    form.render('select');
                    //监听选择框
                    form.on('select(condition)', function () {
                        $.dataCenterList.dataList();
                    });
                });
            },
            getUserInfo: function () {
                getObject(Doman.dataCenterUrl + Doman.getUserInfo + "/" + User.token, false, {}, function (data) {
                    if (data.code == 200) {
                        $("#subject").append($.dataCenterList.selectHtml(data.subjectList));
                        $("#fileType").append($.dataCenterList.selectHtml(data.typeList));
                        $.dataCenterList.subjectList = data.subjectList;
                        $.dataCenterList.initLayui();
                    }
                });
            },
            selectHtml: function (data, val) {
                var html = '';
                $.each(data, function (i, data) {
                    html += '<option ' + (val == data.id ? "selected" : "") + ' value=' + data.id + '>' + data.name + '</option>';
                });
                return html;
            },
            dataList: function (ifPage) {
                var getPage = {
                    content: $("#searchInput").val(),
                    subject: $("#subject").val() || "",
                    type: $("#fileType").val() || "",
                    page: 0,
                    size: 1000,
                    token: User.token
                };
                updateObject(Doman.dataCenterUrl + Doman.getPage, true, JSON.stringify(getPage), function (result) {
                    var html = "";
                    if (result.content.length > 0) {
                        $.each(result.content, function (i, data) {
                            var dataName = data.name + "." + data.extension;
                            html += '<li data-id=' + data.id + ' data-fileurl=' + data.fileUrl + ' data-filename=' + dataName + ' data-extension=' + data.extension + '>'
                            + '    <input type="checkbox" name="" lay-skin="primary" title=' + (i + 1) + "." + data.name + '>'
                            + '    <div class="info">' + data.subjectName + '<span class="time">' + changeDate(data.createTime) + '</span></div>'
                            + '    <span class="check">查看</span>'
                            + '</li>';
                        });
                    }
                    $(".dataList").html(html);
                    $.dataCenterList.initLayui();
                }, function () {
                });
            }
        }
    }();
    $.dataCenterList.init();
})(jQuery);